package com.tzh.plugin.ex;

import com.github.pagehelper.util.StringUtil;
import com.tzh.plugin.utils.GenerateUtils;
import com.tzh.plugin.utils.PluginAnnotationUtils;
import com.tzh.plugin.utils.ServiceUtils;
import com.tzh.utils.PropertiesUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.mybatis.generator.api.GeneratedJavaFile;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.JavaFormatter;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.Interface;
import org.mybatis.generator.api.dom.java.JavaVisibility;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.Parameter;
import org.mybatis.generator.api.dom.java.TopLevelClass;
import org.mybatis.generator.config.TableConfiguration;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

public class ServiceGeneratorPlugin extends PluginAdapter {

    @Override
    public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {

//		String daoType = introspectedTable.getDAOInterfaceType();
        String daotype = introspectedTable.getMyBatis3SqlMapNamespace();
        String classType = introspectedTable.getBaseRecordType();
        String[] pathname = classType.split("\\.");
        String className = pathname[(pathname.length - 1)];
        List<IntrospectedColumn> list = introspectedTable.getAllColumns();
        String pkgPth = introspectedTable.getContext().getJavaModelGeneratorConfiguration().getTargetPackage();
        String[] path = pkgPth.split("\\.");
        StringBuilder serviceBuider = new StringBuilder();
        StringBuilder serviceImplBuider = new StringBuilder();
        StringBuilder controllerBuilder = new StringBuilder();
        StringBuilder dtoBuilder = new StringBuilder();
        List<IntrospectedColumn> promarys = introspectedTable.getPrimaryKeyColumns();
        int length = path.length;
        for (int i = 0; i < length - 1; i++) {
            serviceBuider.append(path[i]);
            if (i < (length - 2)) {
                serviceBuider.append(".");
            } else {
                controllerBuilder.append(serviceBuider);
                controllerBuilder.append(".rest");
                dtoBuilder.append(serviceBuider);
                dtoBuilder.append(".dto");
                serviceBuider.append(".service");
                serviceImplBuider.append(serviceBuider);
                serviceImplBuider.append(".impl");
            }
        }
        String queryDtoPkg = dtoBuilder.toString() + ".query";
        String listDtoPkg = dtoBuilder.toString() + ".list";
        String addDtoPkg = dtoBuilder.toString() + ".add";
        String delDtoPkg = dtoBuilder.toString() + ".del";
        String utDtoPkg = dtoBuilder.toString() + ".modify";
        String detailDtoPkg = dtoBuilder.toString() + ".detail";
        List<GeneratedJavaFile> generatedJavaFiles = new ArrayList<GeneratedJavaFile>();
        GeneratedJavaFile queryDtoGxf = queryDtoGenerate(className, classType, queryDtoPkg, introspectedTable);
        GeneratedJavaFile listDtoGxf = listDtoGenerate(className, classType, listDtoPkg, introspectedTable);
        GeneratedJavaFile addDtoGxf = addDtoGenerate(className, classType, addDtoPkg, introspectedTable);
        GeneratedJavaFile deltoGxf = deltoGenerate(className, classType, delDtoPkg, introspectedTable);
        GeneratedJavaFile uttoGxf = modifyGenerate(className, classType, utDtoPkg, introspectedTable);
        GeneratedJavaFile detailtoGxf = detailGenerate(className, classType, detailDtoPkg, introspectedTable);
        GeneratedJavaFile serviceInterefaceGxf = sericeInterfaceGenerate(promarys, className, classType, serviceBuider.toString(), dtoBuilder.toString());

        generatedJavaFiles.add(queryDtoGxf);
        generatedJavaFiles.add(listDtoGxf);
        generatedJavaFiles.add(addDtoGxf);
        generatedJavaFiles.add(deltoGxf);
        generatedJavaFiles.add(uttoGxf);
        generatedJavaFiles.add(detailtoGxf);
        generatedJavaFiles.add(serviceInterefaceGxf);
        return generatedJavaFiles;
    }

    private static final int DEL_DTO_TYPE = 4;

    private GeneratedJavaFile deltoGenerate(String className, String classType, String delDtoPkg,
                                            IntrospectedTable introspectedTable) {
        TopLevelClass cls = new TopLevelClass(delDtoPkg + ".Del" + className + "Dto");
        cls.addAnnotation("@ApiModel(value = \"" + introspectedTable.getTableConfiguration().getProperties().get(introspectedTable.getFullyQualifiedTableNameAtRuntime() + ":comments") + "删除\" ,description = \"删除操作\")");
        dtoGenerate(cls, introspectedTable, DEL_DTO_TYPE);
        GeneratedJavaFile gxf = new GeneratedJavaFile(cls, context.getJavaModelGeneratorConfiguration().getTargetProject(), context.getJavaFormatter());
        return gxf;
    }

    private static final int ADD_DTO_TYPE = 3;

    private GeneratedJavaFile addDtoGenerate(String className, String classType, String addDtoPkg,
                                             IntrospectedTable introspectedTable) {
        TopLevelClass cls = new TopLevelClass(addDtoPkg + ".Add" + className + "Dto");
        String tableComment = introspectedTable.getTableConfiguration().getProperties().get(introspectedTable.getFullyQualifiedTableNameAtRuntime() + ":comments").toString();
        cls.addAnnotation("@ApiModel(value = \"" + (StringUtils.isEmpty(tableComment) ? introspectedTable.getFullyQualifiedTableNameAtRuntime() : tableComment) + "新增\" ,description = \"新增操作\")");
        dtoGenerate(cls, introspectedTable, ADD_DTO_TYPE);
        GeneratedJavaFile gxf = new GeneratedJavaFile(cls, context.getJavaModelGeneratorConfiguration().getTargetProject(), context.getJavaFormatter());
        return gxf;
    }

    private static final int LIST_DTO_TYPE = 2;

    private GeneratedJavaFile listDtoGenerate(String className, String classType, String targePackage,
                                              IntrospectedTable introspectedTable) {
        TopLevelClass cls = new TopLevelClass(targePackage + ".List" + className + "Dto");
        String tableComment = introspectedTable.getTableConfiguration().getProperties().get(introspectedTable.getFullyQualifiedTableNameAtRuntime() + ":comments").toString();
        cls.addAnnotation("@ApiModel(value = \"" + (StringUtils.isEmpty(tableComment) ? introspectedTable.getFullyQualifiedTableNameAtRuntime() : tableComment) + "查询结果\" ,description = \"查询列表\")");
        dtoGenerate(cls, introspectedTable, LIST_DTO_TYPE);
        GeneratedJavaFile gxf = new GeneratedJavaFile(cls, context.getJavaModelGeneratorConfiguration().getTargetProject(), context.getJavaFormatter());
        return gxf;
    }

    private static final int MOD_DTO_TYPE = 5;

    private GeneratedJavaFile modifyGenerate(String className, String classType, String targePackage,
                                             IntrospectedTable introspectedTable) {
        TopLevelClass cls = new TopLevelClass(targePackage + ".Mod" + className + "Dto");
        String tableComment = introspectedTable.getTableConfiguration().getProperties().get(introspectedTable.getFullyQualifiedTableNameAtRuntime() + ":comments").toString();
        cls.addAnnotation("@ApiModel(value = \"" + (StringUtils.isEmpty(tableComment) ? introspectedTable.getFullyQualifiedTableNameAtRuntime() : tableComment) + "更新\" ,description = \"根据Id跟新数据\")");
        dtoGenerate(cls, introspectedTable, MOD_DTO_TYPE);
        GeneratedJavaFile gxf = new GeneratedJavaFile(cls, context.getJavaModelGeneratorConfiguration().getTargetProject(), context.getJavaFormatter());
        return gxf;
    }


    private static final int DETAIL_DTO_TYPE = 7;

    private GeneratedJavaFile detailGenerate(String className, String classType, String targePackage,
                                             IntrospectedTable introspectedTable) {
        TopLevelClass cls = new TopLevelClass(targePackage + ".Detail" + className + "Dto");
        String tableComment = introspectedTable.getTableConfiguration().getProperties().get(introspectedTable.getFullyQualifiedTableNameAtRuntime() + ":comments").toString();
        cls.addAnnotation("@ApiModel(value = \"" + (StringUtils.isEmpty(tableComment) ? introspectedTable.getFullyQualifiedTableNameAtRuntime() : tableComment) + "详情\" ,description = \"根据Id获取详情\")");
        dtoGenerate(cls, introspectedTable, DETAIL_DTO_TYPE);
        GeneratedJavaFile gxf = new GeneratedJavaFile(cls, context.getJavaModelGeneratorConfiguration().getTargetProject(), context.getJavaFormatter());
        return gxf;
    }

    private static final int QUERY_DTO_TYPE = 1;

    /**
     * 生成列表查询条件参数
     * 若字段为查询条件，id，index，status或字段加了qy
     *
     * @param className
     * @param classType
     * @param targePackage
     * @param introspectedTable
     * @return
     */
    private GeneratedJavaFile queryDtoGenerate(String className, String classType, String targePackage,
                                               IntrospectedTable introspectedTable) {
        TopLevelClass cls = new TopLevelClass(targePackage + ".Query" + className + "Dto");
        String tableComment = introspectedTable.getTableConfiguration().getProperties().get(introspectedTable.getFullyQualifiedTableNameAtRuntime() + ":comments").toString();
        cls.addAnnotation("@ApiModel(value = \"" + (StringUtils.isEmpty(tableComment) ? introspectedTable.getFullyQualifiedTableNameAtRuntime() : tableComment) + "查询参数\" ,description = \"列表查询参数\")");
        dtoGenerate(cls, introspectedTable, QUERY_DTO_TYPE);
        //每页数量
        Field pageSizeFiled = new Field("pageSize", new FullyQualifiedJavaType("java.lang.Integer"));
        pageSizeFiled.setVisibility(JavaVisibility.PRIVATE);
        pageSizeFiled.addAnnotation("@ApiModelProperty(value = \"每页数量\", example = \"10\")");
        cls.addField(pageSizeFiled);
        if (!Boolean.valueOf(PropertiesUtils.getConfigValue("lombok.enabled", "false"))) {
            cls.addMethod(genSetter("pageSize", new FullyQualifiedJavaType("java.lang.Integer")));
            cls.addMethod(genGetter("pageSize", new FullyQualifiedJavaType("java.lang.Integer")));
        }

        //页码
        Field pageNumFiled = new Field("pageNum", new FullyQualifiedJavaType("java.lang.Integer"));
        pageNumFiled.setVisibility(JavaVisibility.PRIVATE);
        pageNumFiled.addAnnotation("@ApiModelProperty(value = \"页码\", example = \"1\")");
        cls.addField(pageNumFiled);
        if (!Boolean.valueOf(PropertiesUtils.getConfigValue("lombok.enabled", "false"))) {
            cls.addMethod(genSetter("pageNum", new FullyQualifiedJavaType("java.lang.Integer")));
            cls.addMethod(genGetter("pageNum", new FullyQualifiedJavaType("java.lang.Integer")));
        }
        //排序方式
        Field orderMethodFiled = new Field("orderMethod", new FullyQualifiedJavaType("java.lang.Integer"));
        orderMethodFiled.setVisibility(JavaVisibility.PRIVATE);
        orderMethodFiled.addAnnotation("@ApiModelProperty(value = \"排序方式 0-逆序 1-正序\", example = \"0\")");
        cls.addField(orderMethodFiled);
        if (!Boolean.valueOf(PropertiesUtils.getConfigValue("lombok.enabled", "false"))) {
            cls.addMethod(genSetter("orderMethod", new FullyQualifiedJavaType("java.lang.Integer")));
            cls.addMethod(genGetter("orderMethod", new FullyQualifiedJavaType("java.lang.Integer")));
        }
        //排序类型
        Field orderTypeFiled = new Field("orderType", new FullyQualifiedJavaType("java.lang.Integer"));
        orderTypeFiled.setVisibility(JavaVisibility.PRIVATE);
        orderTypeFiled.addAnnotation("@ApiModelProperty(value = \"排序类型 0-时间 1-数量\", example = \"0\")");
        cls.addField(orderTypeFiled);
        if (!Boolean.valueOf(PropertiesUtils.getConfigValue("lombok.enabled", "false"))) {
            cls.addMethod(genSetter("orderType", new FullyQualifiedJavaType("java.lang.Integer")));
            cls.addMethod(genGetter("orderType", new FullyQualifiedJavaType("java.lang.Integer")));
        }

        GeneratedJavaFile gxf = new GeneratedJavaFile(cls, context.getJavaModelGeneratorConfiguration().getTargetProject(), context.getJavaFormatter());
        //生成get，set方法

        return gxf;
    }

    private Method genGetter(String fileName, FullyQualifiedJavaType type) {

        char[] nameChars = fileName.toCharArray();
        nameChars[0] -= 32;
        String name = String.valueOf(nameChars);
        Method m2 = new Method("get" + name);
        m2.setVisibility(JavaVisibility.PUBLIC);
        m2.setReturnType(type);
        m2.addBodyLine("return this." + fileName + ";");
        return m2;
    }

    private Method genSetter(String fileName, FullyQualifiedJavaType type) {
        char[] nameChars = fileName.toCharArray();
        nameChars[0] -= 32;
        String name = String.valueOf(nameChars);
        Method m = new Method("set" + name);
        m.addParameter(new Parameter(type, fileName));
        m.setVisibility(JavaVisibility.PUBLIC);
        m.setReturnType(new FullyQualifiedJavaType("void"));
        m.addBodyLine("this." + fileName + "=" + fileName + ";");
        return m;
    }

    private static final ThreadLocal<Boolean> primFlag = new ThreadLocal<Boolean>();

    private static final FullyQualifiedJavaType noArgsConstructorModelAnnotation;

    private static final FullyQualifiedJavaType allArgsConstructorModelAnnotation;

    private static final FullyQualifiedJavaType dataAnnotation;

    static {
        noArgsConstructorModelAnnotation = new FullyQualifiedJavaType(NoArgsConstructor.class.getTypeName());
        allArgsConstructorModelAnnotation = new FullyQualifiedJavaType(AllArgsConstructor.class.getTypeName());
        dataAnnotation = new FullyQualifiedJavaType(Data.class.getTypeName());
    }

    /**
     * @param cls
     * @param introspectedTable
     * @param dtoType           1查询参数 2列表结果集 3.新增 4.删除 5.修改 7-详情
     * @return
     */
    private void dtoGenerate(TopLevelClass cls, IntrospectedTable introspectedTable, int dtoType) {
        cls.addImportedType(new FullyQualifiedJavaType("io.swagger.annotations.ApiModel"));
        cls.addImportedType(new FullyQualifiedJavaType("io.swagger.annotations.ApiModelProperty"));
        if (Boolean.valueOf(PropertiesUtils.getConfigValue("lombok.enabled", "false"))) {
            cls.addImportedType(dataAnnotation);
            cls.addAnnotation("@Data");
            cls.addImportedType(noArgsConstructorModelAnnotation);
            cls.addAnnotation("@NoArgsConstructor");
            cls.addImportedType(allArgsConstructorModelAnnotation);
            cls.addAnnotation("@AllArgsConstructor");
        }
        cls.setVisibility(JavaVisibility.PUBLIC);
        primFlag.set(false);
        List<IntrospectedColumn> columnList = introspectedTable.getBaseColumns();
        if (dtoType != ADD_DTO_TYPE && dtoType != DEL_DTO_TYPE && dtoType != QUERY_DTO_TYPE) {
            List<IntrospectedColumn> primeryKeys = introspectedTable.getPrimaryKeyColumns();
            primeryKeys.forEach(col -> {
//			if(dtoType!=3){
//				primFlag.set(true);
//			}
                String filedName = col.getJavaProperty();
                dtoGeneratePrimeryDBFiled(cls, col, filedName);
            });
        }

        columnList.stream().forEach(col -> {
            String filedName = col.getJavaProperty();
            System.out.println(filedName + "-" + col.isSequenceColumn() + ":" + col.isGeneratedColumn() + ":" + col.isAutoIncrement() + ":" + col.isIdentity());
            switch (dtoType) {
                case QUERY_DTO_TYPE:
                    if ((filedName.toUpperCase().endsWith("ID") && filedName.length() > 2) || filedName.toUpperCase().endsWith("INDEX") || filedName.toUpperCase().contains("STATUS")
                            || filedName.toUpperCase().startsWith("IS") || filedName.startsWith("qy") || filedName.endsWith("Code")) {
                        dtoGenerateDBFiled(cls, col, filedName);
                    }
                    break;
                case LIST_DTO_TYPE:
                    dtoGenerateDBFiled(cls, col, filedName);
                    break;
                case ADD_DTO_TYPE:
                    if (!((filedName.toUpperCase().contains("TIME") || filedName.toUpperCase().contains("DATE")) && !(filedName.toUpperCase().contains("START")) || filedName.toUpperCase().contains("END"))) {
                        dtoGenerateDBFiled(cls, col, filedName);
                    }
                    break;
                case DEL_DTO_TYPE:
                    //||filedName.endsWith("Index")||filedName.endsWith("Code")
                    if (!(filedName.toUpperCase().equals("ID") || filedName.toUpperCase().endsWith("TIME")
                            || filedName.toUpperCase().endsWith("DATE") || filedName.toUpperCase().endsWith("URL")
                            || filedName.toUpperCase().endsWith("LOGO") || filedName.toUpperCase().endsWith("ADDRESS"))) {
                        dtoGenerateDBFiled(cls, col, filedName);
                    }
                    break;
                case MOD_DTO_TYPE:
                    dtoGenerateDBFiled(cls, col, filedName);
                    break;
                case DETAIL_DTO_TYPE:
                    dtoGenerateDBFiled(cls, col, filedName);
                    break;
            }


        });
    }

    private void dtoGenerateDBFiled(TopLevelClass cls, IntrospectedColumn col, String filedName) {
        FullyQualifiedJavaType type = col.getFullyQualifiedJavaType();
        cls.addImportedType(type);
        Field filed = new Field(filedName, col.getFullyQualifiedJavaType());
        TableConfiguration config = col.getIntrospectedTable().getTableConfiguration();
        Properties prop = config.getProperties();
        String comments = "...";
        String length = "0";
        if (prop != null) {
            String columnDbName = col.getActualColumnName();
            Object obj = prop.get(col.getIntrospectedTable().getAliasedFullyQualifiedTableNameAtRuntime() + ":" + columnDbName);
            if (obj != null) {
                String propValue = obj.toString();
                String[] propArray = propValue.split(":", 3);
                length = propArray[1];
                comments = propArray[2];
                if (StringUtil.isEmpty(comments) || "null".equals(comments)) {
                    comments = "---";
                }
            }

        }
        filed.addAnnotation("@ApiModelProperty(value = \"" + comments + "\"" + (StringUtils.isEmpty(col.getDefaultValue()) ? ",example = \"" + PluginAnnotationUtils.setExample(col) + "\"" : ",example = \"" +
                col.getDefaultValue().replace("\\", "|").replace("\n", "") + "\"") + (primFlag.get() ? ", required=true" : "") + ")");
        primFlag.set(false);
        filed.setVisibility(JavaVisibility.PRIVATE);
        cls.addField(filed);
        //setter
        if (!Boolean.valueOf(PropertiesUtils.getConfigValue("lombok.enabled", "false"))) {
            cls.addMethod(genSetter(filedName, type));
            //getter
            cls.addMethod(genGetter(filedName, type));
        }
    }

    private void dtoGeneratePrimeryDBFiled(TopLevelClass cls, IntrospectedColumn col, String filedName) {
        FullyQualifiedJavaType type = col.getFullyQualifiedJavaType();
        cls.addImportedType(type);
        Field filed = new Field(filedName, col.getFullyQualifiedJavaType());
        TableConfiguration config = col.getIntrospectedTable().getTableConfiguration();
        Properties prop = config.getProperties();
        String comments = "...";
        String length = "0";
        if (prop != null) {
            String columnDbName = col.getActualColumnName();
            Object obj = prop.get(col.getIntrospectedTable().getAliasedFullyQualifiedTableNameAtRuntime() + ":" + columnDbName);
            if (obj != null) {
                String propValue = obj.toString();
                String[] propArray = propValue.split(":", 3);
                length = propArray[1];
                comments = propArray[2];
                if (StringUtil.isEmpty(comments) || "null".equals(comments)) {
                    comments = "---";
                }
            }

        }
        filed.addAnnotation("@ApiModelProperty(value = \"" + comments + "\"" + (StringUtils.isEmpty(col.getDefaultValue()) ? ",example = \"" + PluginAnnotationUtils.setExample(col) + "\"" : ",example = \"" +
                col.getDefaultValue().replace("\\", "|").replace("\n", "") + "\"") + (primFlag.get() ? ", required=true" : "") + ")");
        primFlag.set(false);
        filed.addAnnotation(setValidAnno(cls, col));
        filed.setVisibility(JavaVisibility.PRIVATE);
        cls.addField(filed);
        //setter
        if (!Boolean.valueOf(PropertiesUtils.getConfigValue("lombok.enabled", "false"))) {
            cls.addMethod(genSetter(filedName, type));
            //getter
            cls.addMethod(genGetter(filedName, type));
        }
    }

    private static String setValidAnno(TopLevelClass cls, IntrospectedColumn introspectedColumn) {
        FullyQualifiedJavaType type = introspectedColumn.getFullyQualifiedJavaType();
        String typeName = type.getFullyQualifiedName();
        String shortType = Short.class.getName();
        String intType = Integer.class.getName();
        String LongType = Long.class.getName();
        String doubleType = Double.class.getName();
        String dateType = Date.class.getName();
        String bigDType = BigDecimal.class.getName();
        if (typeName.equals(shortType)) {
            cls.addImportedType(new FullyQualifiedJavaType(NotNull.class.getName()));
            return "@NotNull(message=\"{param.number.not.null}\")";
        } else if (typeName.equals(intType)) {
            cls.addImportedType(new FullyQualifiedJavaType(NotNull.class.getName()));
            return "@NotNull(message=\"{param.number.not.null}\")";
        } else if (typeName.equals(LongType)) {
            cls.addImportedType(new FullyQualifiedJavaType(NotNull.class.getName()));
            return "@NotNull(message=\"{param.number.not.null}\")";
        } else if (typeName.equals(dateType)) {
            cls.addImportedType(new FullyQualifiedJavaType(NotNull.class.getName()));
            return "@NotNull(message=\"{param.number.not.null}\")";
        } else if (typeName.equals(bigDType)) {
            cls.addImportedType(new FullyQualifiedJavaType(NotNull.class.getName()));
            return "@NotNull(message=\"{param.number.not.null}\")";
        } else if (typeName.equals(String.class.getName())) {
            cls.addImportedType(new FullyQualifiedJavaType(NotEmpty.class.getName()));
            return "@NotEmpty(message=\"{param.string.not.empty}\")";
        } else {
            cls.addImportedType(new FullyQualifiedJavaType(NotNull.class.getName()));
            return "@NotNull(message=\"{param.number.not.null}\")";
        }
    }


    @Override
    public boolean validate(List<String> warnings) {
        return true;
    }

    private GeneratedJavaFile sericeInterfaceGenerate(List<IntrospectedColumn> promarys, String className, String classType, String targePackage, String dtoPath) {
        Interface serviceInterface = new Interface(new FullyQualifiedJavaType(targePackage + ".I" + className + "Service"));
        serviceInterface.setVisibility(JavaVisibility.PUBLIC);
        //引包
        Map<String, FullyQualifiedJavaType> dtoData = new HashMap<String, FullyQualifiedJavaType>();
        GenerateUtils.setImports(serviceInterface, dtoPath, className, classType, dtoData);
        //方法
        Method queryMethod = ServiceUtils.generateMethod(className, dtoPath, "query" + className + "List", 1);
        queryMethod.setAbstract(true);
        serviceInterface.addMethod(queryMethod);
        Method addMethod = ServiceUtils.generateMethod(className, dtoPath, "add" + className, 3);
        addMethod.setAbstract(true);
        serviceInterface.addMethod(addMethod);
        Method delMethod = ServiceUtils.generateMethod(className, dtoPath, "del" + className, 4);
        delMethod.setAbstract(true);
        serviceInterface.addMethod(delMethod);
        Method modMethod = ServiceUtils.generateMethod(className, dtoPath, "update" + className, 5);
        modMethod.setAbstract(true);
        serviceInterface.addMethod(modMethod);
        if (promarys != null && promarys.size() > 0) {
            Method delByIdMethod = ServiceUtils.generateMethod(promarys, className, dtoPath, "del" + className, 6);
            delByIdMethod.setAbstract(true);
            serviceInterface.addMethod(delByIdMethod);
            Method detailMethod = ServiceUtils.generateMethod(promarys, className, dtoPath, "select" + className + "Detail", 7);
            detailMethod.setAbstract(true);
            serviceInterface.addMethod(detailMethod);
        }
        GeneratedJavaFile gxf = null;
        try {
            JavaFormatter format = context.getJavaFormatter();
            System.out.println(format.getFormattedContent(serviceInterface));
            gxf = new GeneratedJavaFile(serviceInterface, context.getJavaModelGeneratorConfiguration().getTargetProject(), context.getJavaFormatter());

        } catch (Exception e) {
            e.printStackTrace();
        }
        return gxf;

    }
}
